<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="id">
        <input type="text" id="input">
        <p class="text" id="p">0</p>
    </div>


    <script>
        let input = document.getElementById('input')
        let p = document.getElementById('p')
        let obj = {}
        
        Object.defineProperty(obj, 'text', {  // 数据劫持
            enumerable: true,
            configurable: true,
            get() {
                console.log('获取数据了');
            },
            set(newVal) {
                console.log('数据更新了');
                input.innerHTML = newVal
                p.innerHTML = newVal
            }
        })

        input.addEventListener('keyup', (e) => {
            console.log(e.target.value);
            obj.text = e.target.value
        })
    </script>
</body>
</html>